<!DOCTYPE>
<html>
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="/layer/layer.js"></script>
</head>

<body>
<div id="app">
    <nav class="navbar navbar-inverse" style="border-radius: 0">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
                        aria-expanded="false" aria-controls="navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">小黑资源系统</a>
            </div>

            <div id="navbar" class="collapse navbar-collapse">
                <ul class="nav navbar-nav">
                    <li class="active"><a href="/index.html">首页</a></li>
                    <li v-for="d in userResources" v-if="d.pid==0">
                        <!--  “v-...” 指的是vue里面的东西，主要用于ajax的内容显示  -->
                        <a v-bind:href="d.url">{{d.name}}</a>
                    </li>
                </ul>
                <ul class="nav navbar-nav navbar-right hidden-sm">
                    <li><a>欢迎您：{{userName}}</a></li>
                    <!--      "{{}}" 里面放       -->
                    <li><a @click="logout()" href="#">退出</a></li>

                </ul>
            </div>
        </div>
    </nav>

    <div class="starter-template" style="text-align: center">
        <h1>欢迎进入小黑用户管理系统</h1>
        <p class="lead">
            本系统为的减少您不必要的操作，人性化的展现每个操作作用，把省下来的时间还给您<br>
        <h4>每天都是一生中最好的日子。愿我们珍惜年华,把握今天。</h4>
        </p>
    </div>
</div>


<script>
    new Vue({
        el: "#app",
        data: {
            userResources: [],
            userName: ''
        },
        created() {
            this.getUserInfo();
        },
        methods: {
            getUserInfo() {
                var vm = this;
                $.post("userInfo", {}, function (response) {
                    if (response.code == 200) {
                        vm.userName = response.data.name
                        vm.userResources = response.data.role.resourceList
                    } else {
                        location.href = "login.html"
                    }
                })
            },
            //退出
            logout() {
                $.post("/logout", {}, function (response) {
                    // location.href = "login.html"
                    layer.msg('退出成功！', {
                        time: 500,
                        end: function () {
                            location.href = "/login.html"
                        }
                    })
                })
            }
        }
    })
</script>
</body>
</html>